package com.lxd.mybatisplus.controller;

import com.lxd.mybatisplus.entity.User;
import com.lxd.mybatisplus.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author liuxiaoding
 * @Date 2019/11/19
 **/
@RestController
@RequestMapping(value = "user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 批量获取用户
     * @return
     */
    @RequestMapping("/getList")
    public List<User> getList(){
        List<User> userInfoEntityList = userService.list();
        return userInfoEntityList;
    }

    /**
     * 根据id获取用户信息
     * @param userId
     * @return
     */
    @RequestMapping("/getUser")
    public User getUser(Integer userId){
        return userService.getById(userId);
    }

    /**
     * 添加用户返回主键
     * @param user
     * @return
     */
    @RequestMapping("/addUser")
    public String addUser(User user){
        userService.save(user);
        return "主键id："+user.getId();
    }

    /**
     * 删除
     * @param userId
     * @return
     */
    @RequestMapping("/delete")
    public boolean delete(Integer userId){
        return userService.removeById(userId);
    }

    /**
     * 根据id更新
     * @param user
     * @return
     */
    @RequestMapping(value = "update")
    public boolean update(User user){
        return userService.updateById(user);
    }
}
